<%@page contentType="text/html;charset=utf-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>   
<script type="text/javascript">
function manage_productcode_savecode(type)
{
    var name = document.getElementById("model.productCodeName").value;
    var codeid = dijit.byId("model.spCodeId").get('value');
    if (name == null || name == "" || codeid == null || codeid == "")
    {
        alert("信息不完整！");
        return false;
    }

    if (!confirm("确定继续？"))
    {
        return false;
    }
    var url = "mg/productcode/save.do?type=" + type;
    var objectid = "manage_product_showcode";
    postXMLHttpRequest(url, "myform", objectid); 
}

function manage_productcode_selectsp()
{   
	var sp_id = dijit.byId("model.spId").get('value');
	if (sp_id == null || sp_id == "")
	{
		return;
	}
	
	var url = "mg/productcode/selectsp.do";
    var content = "model.spId=" + sp_id;
    var objectid = "manage_productcode_spcodelist";
    sendXMLHttpRequest(url, content, objectid); 
}
function manage_productcode_select_spcode()
{
	var cn = dijit.byId("model.spCodeId").get("displayedValue");
	
	var sp_id = dijit.byId("model.spId").get('value');
	var sp_code_id =  dijit.byId("model.spCodeId").get('value');
	document.getElementById("feelinkdiv").innerHTML="&nbsp;&nbsp;"+getSelectedTextByValue("spCodeIddis",sp_code_id);

	document.getElementById("model.productCodeName").value=cn +"("+document.getElementById("project.name").value+")";	
		
	 
	if (sp_id == null || sp_id == ""
		|| sp_code_id == null || sp_code_id == "")
	{
		return;
	}
	
	var url = "mg/productcode/selectspcode.do";
    var content = "model.productId=" + document.getElementById("model.productId").value
                + "&model.id=" + document.getElementById("model.id").value
                + "&model.spId=" + sp_id 
    			+ "&model.spCodeId=" + sp_code_id;
    var objectid = "manage_productcode_open_province";
    sendXMLHttpRequest(url, content, objectid);
}
function manager_productcode_checkcodeprovince(obj)
{
	if (obj.checked == true)
	{
		var caption = document.getElementById("open_province_caption");
		if (caption.style.display == "none")
			caption.style.display = "";
		document.getElementById("open_province_" + obj.value).style.display = "";
	}
	else
	{
		document.getElementById("open_province_" + obj.value).style.display = "none";
		var b = false;
		var ckbs = document.getElementsByName("model.productCodeOpenProvince");
		for (var n = 0; n < ckbs.length; n++)
		{
			if (ckbs[n].checked == true)
			{
				b = true;
				break;
			}
		}
		if (b == false)
			document.getElementById("open_province_caption").style.display = "none";
	}
}
function manage_productcode_checkallprovince(obj)
{
	var ckbs = document.getElementsByName("model.productCodeOpenProvince");
	if (obj.checked == true)
	{
		var caption = document.getElementById("open_province_caption");
		if (caption.style.display == "none")
			caption.style.display = "";
		for (var n = 0; n < ckbs.length; n++)
		{
			ckbs[n].checked = true;
			document.getElementById("open_province_" + ckbs[n].value).style.display = "";
		}
	}
	else
	{
		document.getElementById("open_province_caption").style.display = "none";
		for (var n = 0; n < ckbs.length; n++)
		{
			ckbs[n].checked = false;
			document.getElementById("open_province_" + ckbs[n].value).style.display = "none";
		}
	}
}

function getSelectedTextByValue(name,value){
	var obj=document.getElementById(name);
	for(var i=0;i<obj.length;i++){
	   if(obj[i].value==value){
	    return obj[i].text;
	   }
	}
}
function getSelectedLabelByValue(name,value){
	var obj=document.getElementById(name);
	for(var i=0;i<obj.length;i++){
	   if(obj[i].value==value){
	    return obj[i].label; 
	   }
	}
}
function getSelectedTitleByValue(name,value){
	var obj=document.getElementById(name);
	for(var i=0;i<obj.length;i++){
	   if(obj[i].value==value){
	    return obj[i].title; 
	   }
	}
}
</script>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="5"></td>
    <td>   
  <form id="myform" name="myform">
  
  <input id="model.id" name="model.id" type="hidden" value="<s:property value="model.id" />"/>
        <input id="model.productCodeStatus" name="model.productCodeStatus" type="hidden" value="<s:property value="model.productCodeStatus" />"/>
        <input id="model.createUser" name="model.createUser" type="hidden" value="<s:property value="model.createUser" />"/>
        <input id="model.createDate" name="model.createDate" type="hidden" value="<s:property value="model.createDate" />"/>
        <input id="model.productId" name="model.productId" type="hidden" value="<s:property value="model.productId" />"/>  
        
        
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="3">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="images/table_top_left.jpg" width="20" height="15" /></td>
            <td><img src="images/table_top_bg.jpg" width="770" height="15"/></td>
            <td align="right">
              <img src="images/table_top_right.jpg" width="20" height="15" /></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td height="25" colspan="3" class="table_blue">
        <strong><img src="images/dot.jpg" width="13" height="9">计费信息</strong>       
        </td>        
    </tr> 
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>通道：</td>
      <td class="table_w2" colspan="2">&nbsp;
      <select id="model.spId" name="model.spId" dojoType="dijit.form.FilteringSelect"
           style="width:280px;" onchange="manage_productcode_selectsp()">
           <s:if test="splist.size()!=1">
		    <option value="">请选择</option>
		    </s:if>
           <s:if test="splist.size()>0">
           <s:iterator value="splist" status="stat1">
           <s:set name="spId" value="model.spId" />
           <option value="<s:property value="id" />" <s:if test="id.equals(#spId)">selected</s:if> ><s:property value="spName" /></option>
           </s:iterator>
           </s:if>
        </select>
      </td>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>代码：</td>
      <td class="table_w2" colspan="2" valign="top">&nbsp;<div id="manage_productcode_spcodelist" style="height:100%;margin-top:0;">&nbsp;
      		<select id="model.spCodeId" name="model.spCodeId" dojoType="dijit.form.FilteringSelect" style="width:280px;" onchange="manage_productcode_select_spcode()">
            <s:if test="spcodelist.size()!=1">
		    <option value="">请选择</option>
		    </s:if>
		    <s:if test="spcodelist.size()>0">
		    <s:iterator value="spcodelist" status="stat2">
		    	<option value="<s:property value="id" />" ><s:property value="codeName" /></option>
		    </s:iterator>
		    </s:if>
	    </select><div id="spCodeIddisdiv" style="display:none;"><select id="spCodeIddis" name="spCodeIddis" 
            style="width:280px;" style="display:none;">
            <s:if test="spcodelist.size()!=1">
		    <option value="">请选择</option>
		    </s:if>
		    <s:if test="spcodelist.size()>0">
		    <s:iterator value="spcodelist" status="stat2">
		    	<option value="<s:property value="id" />" title="<s:property value="entranceLink" />" label="<s:property value="loginLink" />"><s:property value="feeLink" /></option>
		    </s:iterator>
		    </s:if>
	    </select></div>
	    </div>
      </td>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>名称：</td>
      <td class="table_w2" colspan="2">&nbsp;
        <input id="model.productCodeName" name="model.productCodeName" type="text" size="60"
          value="<s:property value="model.productCodeName" />"/></td>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>优先级别：</td>
      <td class="table_w2" colspan="2">&nbsp;
        <input id="model.level" name="model.level" type="text" size="60"
          value="<s:property value="model.level" />"/><font color="red">默认为0，数字越大表示优先选择该代码</font></td>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>计费链接：</td>
      <td class="table_w2" colspan="2" valign="top">&nbsp;&nbsp;<div id="feelinkdiv" style="height:100%;margin-top:0;">&nbsp;&nbsp;<s:property value="model.feeLink" /></div></td>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>开通省份：<input type="checkbox" onclick="manage_productcode_checkallprovince(this);" /></td>
      <td class="table_w2" colspan="2">
        <div id="manage_productcode_open_province"><%@include file="_selectspcode.jsp" %>
        </div>
      </td>
    </tr>
    <tr>
      <td colspan="3" class="table_w1" align="center">
        <s:if test="type.equals('insert')">
        <button id="btn3" dojoType="dijit.form.Button"
            onclick="return manage_productcode_savecode('insert');">添加</button>
        </s:if>
        <s:else>
        <button id="btn3" dojoType="dijit.form.Button"
            onclick="return manage_productcode_savecode('update');">修改</button>
        &nbsp;&nbsp;        
        <s:if test='%{model.productCodeStatus=="0"}'>     
        <button id="btn4" dojoType="dijit.form.Button"
            onclick="return manage_productcode_savecode('delete');">停用</button>
        </s:if>
        <s:else>
        <button id="btn4" dojoType="dijit.form.Button"
            onclick="return manage_productcode_savecode('restore');">启用</button>
        </s:else>
        </s:else>
      </td>      
    </tr>
    <tr> 
      <td colspan="3" background="images/table_bom_bg.jpg">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><img src="images/table_bom_left.jpg" width="20" height="15"></td>
          <td></td>
          <td align="right">
            <img src="images/table_bom_right.jpg" width="20" height="15"></td>
        </tr>
        </table>
      </td>
    </tr>
  </table>  
  </form>
  </td>
  <td width="5"></td>
  </tr>
  </table>
  <div id="manage_sp_codelog"></div>